import {addShare, getRemoteUserInfo} from './api/index'
import {getCurrentPageUrl} from './utils/get-current-route'
//app.js
App({
  onShow (opts) {
    console.log('onShow share', opts)
    // 分享
    if (opts.query.id) {
      addShare({id: opts.query.id})
    }
    // 记录分享人openid
    if (opts.query.openid) {
      wx.setStorageSync('shared_openid', opts.query.openid)
    }
    this.updateGlobalData()
  },
  updateGlobalData (cb) {
    getRemoteUserInfo().then(res => {
      console.log(5, res)
      let _info = res.data.info
      this.globalData.is_verify = _info.is_verify
      this.globalData.userInfo = _info
      if (_info.group_id == 0) {
        if (getCurrentPageUrl() !== '/pages/init/index') {
          wx.navigateTo({
            url: '/pages/init/index'
          })
        }
      }
      cb && cb(_info)
    }).catch(err => {
      console.log(err)
    })
  },
  globalData: {
    is_verify: 0,
    userInfo: null
  }
})
